package br.com.android.financas;

import java.sql.SQLException;

import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.preference.PreferenceManager;
import br.com.android.financas.repositorio.RepositorioPoupanca;
import br.com.android.financas.repositorio.impl.RepositorioPoupancaImpl;

public class AtualizaPoupancaServico extends Service {

	private RepositorioPoupanca repositorioPoupanca;

	public AtualizaPoupancaServico() {
	}

	@Override
	public IBinder onBind(Intent intent) {
		// TODO: Return the communication channel to the service.
		throw new UnsupportedOperationException("Not yet implemented");
	}

	@Override
	public void onCreate() {

	}

	@Override
	public void onStart(Intent intent, int startId) {
		try {
			repositorioPoupanca=new RepositorioPoupancaImpl(getApplicationContext());

			SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
			if(preference.getBoolean("bcc", false)){
				WebServicePoupanca web=new WebServicePoupanca(getApplicationContext(),false);
				preference.edit().putString("taxaJuros", Float.toString(web.getPercentual()));
			}
			repositorioPoupanca.atualizaPorJuros();

		} catch (SQLException e) {
			e.printStackTrace();
		}

	}

}